package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: 移动端的controller
 * @author: wangjingliang
 * @create: 2019-11-18 19:08
 **/
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference
    private SetmealService setmealService;

    /**
     * 查询所有套餐信息
     * url:/setmeal/getAllSetmeal.do
     *
     * @param:
     * @return: null
     * @date: 2019/11/18
     */
    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal() {
        try {
            List<Setmeal> setmealList = setmealService.findAll();
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL, e.getMessage());
        }
    }

    /**
     * 根据id查询套餐和检查项和检查组
     * url://setmeal/findById.do?id=
     *
     * @param:
     * @return: null
     * @date: 2019/11/18
     */
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        try {
            Setmeal setmeal = setmealService.findById(id);
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL, e.getMessage());
        }
    }

    /**
     * 根据id查询套餐
     * url:/setmeal/findsetmealById.do?id
     *
     * @param:
     * @return: null
     * @date: 2019/11/19
     */
    @RequestMapping("/findsetmealById")
    public Result findsetmealAllById(Integer id) {
        try {
            Setmeal setmeal = setmealService.findsetmealById(id);
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL, e.getMessage());
        }
    }

}
